UserEditPortlet = Class.extend({
	init: function()	{
		this.name = "UserEditPortlet";
	},
	
	onBegin: function()	{
		this.registerObserver();
	},
	
	onEnd: function()	{
		this.unregisterObserver();
	},
	
	onReloadPage: function()	{
		this.run();
	},
	
	run: function()	{
		//store the current object
		var obj = this;
		var id = this.getRequest().getParam('id');
		this.onAjax('user', 'view-info', {id: id}, 'GET', {
			'onSuccess': function(ret)	{
				obj.model = ret;
				obj.model.female = "";
				obj.model.male = "";
				if (ret.gender == 0)
					obj.model.female = "checked";
				else
					obj.model.male = "checked";
				var d = ret.dob_day;
				var m = ret.dob_month;
				var y = ret.dob_year;
				
				obj.model.year = y;
				obj.getPortletPlaceholder().paintCanvas(obj.render());
				
				var result = "";
				for(var i=1;i<=31;i++)	{
					result += "<option value='"+i+"'>"+i+"</option>";
				}
				obj.requestForEffectiveResource('DayOfBirth').append(result);
				obj.requestForEffectiveResource('DayOfBirth').val(d);
				
				var result = "";
				for(var i=1;i<=12;i++)	{
					result += "<option value='"+i+"'>"+i+"</option>";
				}
				obj.requestForEffectiveResource('MonthOfBirth').append(result);
				obj.requestForEffectiveResource('MonthOfBirth').val(m);
			}
		});
	},
	
	onEditProfileClicked: function()	{
		var fullname = this.requestForEffectiveResource('Fullname').val();
		var gender = $('input[name=gender]:checked').val();
		var day = this.requestForEffectiveResource('DayOfBirth').val();
		var month = this.requestForEffectiveResource('MonthOfBirth').val();
		var year = this.requestForEffectiveResource('YearOfBirth').val();
		var hobbies = this.requestForEffectiveResource('Hobbies').val();
		
		this.onAjax('user', 'edit-info', {fullname: fullname, gender: gender, dob_day: day, dob_month: month, dob_year: year, hobbies: hobbies}, 'POST', {
			'onSuccess': function(ret)	{
				alert('Cập nhật thành công');
			}
		});
	}
}).implement(PortletInterface).implement(RenderInterface).implement(AjaxInterface).implement(ObserverInterface);